import React, { Component, Fragment } from 'react';
import { connect } from 'dva';
import { Form, Row, Col, Input } from 'antd';
import StandardTable from '@/components/StandardTable';
import AdModal from '@/components/AdModal';
import moment, { isDate } from 'moment';
import AntdForm from '@/components/AntdForm';
import AdSelect from '@/components/AdSelect';
import AdButton from '@/components/AdButton';
import AntdFormItem from '@/components/AntdFormItem';
import AntdInput from '@/components/AntdInput';
import AdSearch from '@/components/AdSearch';
import AntdDatePicker from '@/components/AntdDatePicker';
import {
  queryDictData,
  formatFile,
  vitifyCheck,
  queryDict,
  formateDateToMin,
  formatPrice,
} from '@/utils/common';
import { allDictList, billStateOnlyReadList } from '@/utils/constans';
import TableButtons from '@/components/TableButtons';
import SelectForm from '@/components/SelectForm';
import SearchSelect from '@/components/SearchSelect';
import { columns1, columnsDriver, supplierColumns } from '@/pages/Common/common';
import {
  allDispatchType,
  selectBillDetailAndInfo,
  renderTableAdSelect,
  codes,
  caclTotal,
  getBillVehicleIDetails,
  getBillOilDetails,
  upkeepPayMethod,
  saveAllValues,
  renderTableAdSearch,
  allUrl,
  incidentalStatusList,
} from './utils';
import BillInfoDetail from './BillInfoDetail';
import FileReader from '@/components/FileReader';
import styles from './Bill.less';

@connect(({ vehicle, component, loading }) => ({
  billInfo: vehicle.billInfo,
  billDetail: vehicle.billDetail,
  billAddInfo: vehicle.billAddInfo,
  dictObject: component.dictObject,
  loading: loading.effects[allDispatchType.addInfo],
  addLoading: loading.effects[allDispatchType.info],
}))
@Form.create()
export default class BillInfo extends Component {
  state = {
    detailId: '',
    selectedRows: [],
    addSelectedRows: [],
    checkId: '',
    type: '',
    cars: [],
    drivers: [],
    company: [],
    formValues: {},
  };

  componentDidMount() {
    const { dispatch, billDetail, detailId, open } = this.props;
    const details = billDetail[detailId] || {};
    const id = open ? details.id : detailId;
    this.setState({
      id,
    });
    // getBillOilDetails(dispatch, id, open);
    details.type && this.selectBillDetailAndInfo(id, details.type);
  }

  componentWillMount() {
    const allDict = [
      allDictList.oilType,
      allDictList.inspectionType,
      allDictList.upkeepType,
      allDictList.insuranceType,
      allDictList.insuranceObject,
      allDictList.etcChangeType,
      allDictList.papersType,
      allDictList.otherFeeType,
    ];
    queryDict({ props: this.props, allDict });
  }

  componentWillReceiveProps(nextProps, nextState) {
    const { detailId, billDetail, visible } = nextProps;
    const detail = billDetail[detailId];
    if (detailId && !nextState.detailId && detail) {
      this.handleStateChange([{ detailId: detail.id }]);
    }
    if (
      JSON.stringify(billDetail) !== JSON.stringify(this.props.billDetail) ||
      this.props.detailId !== detailId
    ) {
      if (detailId && detail) {
        this.handleStateChange([{ type: detail.type, detailId: detail.id }]);
        this.selectBillDetailAndInfo(detail.id, detail.type);
      }
    }
    if (this.props.visible !== visible && visible) {
      this.seleceBillAddInfo();
    }
  }

  seleceBillAddInfo = (param = {}) => {
    const { dispatch, detailId, billDetail } = this.props;
    const detail = billDetail[detailId];
    const type = detail ? detail.type : '';
    if (!type) return;
    if (type === 'INSURANCE' || type == 'OIL') {
      param.ownCompanyId = detail.mdsCompanyId;
    } else {
      param.mdsCompanyId = detail.mdsCompanyId;
    }
    dispatch({
      type: allDispatchType.addInfoList,
      payload: {
        type,
        yetBill: false,
        ...param,
      },
    });
  };

  selectBillDetailAndInfo = (detailId, type, params) => {
    const { open } = this.props;
    selectBillDetailAndInfo({
      type: allDispatchType.info,
      payload: { billId: detailId, type, open, ...params },
      props: this.props,
      callback: data => {
        //司机证件
        if (type == 'DRIVERPAPER') {
          queryPerson({ data, props: props, url: allUrl.userList });
        }
      },
    });
  };
  //详情
  showDetail = (checkId, recordStatus) => {
    this.handleStateChange([{ checkId }, { recordStatus }, { visibleDetail: true }]);
  };
  handleCandle = () => {
    this.setState({
      visibleDetail: false,
    });
  };

  renderInfo = (text, record) => {
    const { mode, open } = this.props;
    const _text = <a>{text}</a>;
    return (
      <AdButton
        mode="a"
        onClick={() => this.showDetail(record.id, record.status)}
        text={open ? _text : text}
        code={codes.showDetail}
      />
    );
  };

  handleStateChange = (options = []) => {
    options.map(item => {
      this.setState(item);
    });
  };

  oilColumns = [
    {
      title: '单据号',
      dataIndex: 'oilNo',
      render: (text, record) => this.renderInfo(text, record),
    },
    {
      title: '主车牌',
      dataIndex: 'cartPlateNo',
    },
    {
      title: '加油时间',
      dataIndex: 'oilTime',
    },
    {
      title: '加油站',
      dataIndex: 'oilSiteName',
    },
    {
      title: '加油方式',
      dataIndex: 'oilType',
      render: text =>
        renderTableAdSelect({ props: this.props, value: text, key: allDictList.oilType }),
    },
    {
      title: '当前里程(KM)',
      dataIndex: 'mileage',
    },
    {
      title: '加油量（L）',
      dataIndex: 'oilAmount',
    },
    {
      title: '单价',
      dataIndex: 'price',
    },
    {
      title: '币种',
      dataIndex: 'currencyType',
      render: text =>
        renderTableAdSelect({
          props: this.props,
          value: text,
          key: allDictList.currencyType,
        }),
    },
    {
      title: '金额',
      dataIndex: 'totalFee',
    },
    {
      title: '油耗',
      dataIndex: 'avgHundredConsump',
    },
    {
      title: '附件',
      dataIndex: 'attaQuantity',
      render: (text, record) => (
        <FileReader
          type="list"
          count={text}
          urlType="tms"
          params={{ bizId: record.id, fileBizType: 'OIL_MANA' }}
        />
      ),
    },
  ];

  insuranceColumns = [
    {
      title: '单据号',
      dataIndex: 'insuranceNo',
      render: (text, record) => this.renderInfo(text, record),
    },
    {
      title: '保险对象',
      dataIndex: 'insuranceObject',
      render: text =>
        renderTableAdSelect({ props: this.props, value: text, key: allDictList.insuranceObject }),
    },
    {
      title: '代理购买保险人',
      dataIndex: 'agentPurchaser',
    },
    {
      title: '主车牌',
      dataIndex: 'cartPlateNo',
    },
    {
      title: '所属公司',
      dataIndex: 'ownCompanyName',
    },
    {
      title: '保险类型',
      dataIndex: 'insuranceTypeCode',
      render: text =>
        renderTableAdSelect({ props: this.props, value: text, key: allDictList.insuranceType }),
    },
    {
      title: '保险公司',
      dataIndex: 'company',
    },
    {
      title: '保单号',
      dataIndex: 'insuranceCode',
    },
    {
      title: '有效期',
      dataIndex: 'expiryTime',
      render: (_, record) => <span>{`${record.expiryStartTime}~${record.expiryEndTime}`}</span>,
    },
    {
      title: '保费金额',
      dataIndex: 'insuranceMoney',
    },
    {
      title: '币种',
      dataIndex: 'currencyType',
      render: text =>
        renderTableAdSelect({
          props: this.props,
          value: text,
          key: allDictList.currencyType,
        }),
    },
    {
      title: '附件',
      dataIndex: 'attaQuantity',
      render: (text, record) => (
        <FileReader
          type="list"
          count={text}
          urlType="tms"
          params={{ bizId: record.id, fileBizType: 'INSURANCE_MANA' }}
        />
      ),
    },
  ];

  verificationColumns = [
    {
      title: '单据号',
      dataIndex: 'annualNo',
      render: (text, record) => this.renderInfo(text, record),
    },
    {
      title: '主车牌',
      dataIndex: 'cartPlateNo',
    },
    {
      title: '所属公司',
      dataIndex: 'ownCompanyName',
    },
    {
      title: '类型',
      dataIndex: 'annualAuditType',
      render: text =>
        renderTableAdSelect({ props: this.props, value: text, key: allDictList.inspectionType }),
    },
    {
      title: '有效期',
      dataIndex: 'expiryTime',
      render: (_, record) => <span>{`${record.expiryStartTime}~${record.expiryEndTime}`}</span>,
    },
    {
      title: '费用',
      dataIndex: 'feeCost',
    },
    {
      title: '币种',
      dataIndex: 'currencyType',
      render: text =>
        renderTableAdSelect({
          props: this.props,
          value: text,
          key: allDictList.currencyType,
        }),
    },
    {
      title: '年审时间',
      dataIndex: 'yearAuditTime',
    },
    {
      title: '附件',
      dataIndex: 'attaQuantity',
      render: (text, record) => (
        <FileReader
          type="list"
          count={text}
          urlType="tms"
          params={{ bizId: record.id, fileBizType: 'YEARAUDIT_MANA' }}
        />
      ),
    },
  ];

  upkeepColumns = [
    {
      title: '单据号',
      dataIndex: 'upkeepNo',
      render: (text, record) => this.renderInfo(text, record),
    },

    {
      title: '主车牌',
      dataIndex: 'cartPlateNo',
    },
    {
      title: '所属公司',
      dataIndex: 'ownCompanyName',
    },
    {
      title: '里程数',
      dataIndex: 'currentMileage',
    },
    {
      title: '应付币种',
      dataIndex: 'currencyType',
      render: text =>
        renderTableAdSelect({
          props: this.props,
          value: text,
          key: allDictList.currencyType,
        }),
    },
    {
      title: '应付金额',
      dataIndex: 'totalFee',
      render: text => {
        return <span>{text && Number(text) !== 0 ? Number(text).toFixed(2) : ''}</span>;
      },
    },
    {
      title: '实付币种',
      dataIndex: 'realCurrencyType',
      render: text =>
        renderTableAdSelect({
          props: this.props,
          value: text,
          key: allDictList.currencyType,
        }),
    },
    {
      title: '实付金额',
      dataIndex: 'realPayFee',
      render: text => {
        return <span>{text && Number(text) !== 0 ? Number(text).toFixed(2) : ''}</span>;
      },
    },
    {
      title: '类型',
      dataIndex: 'upkeepType',
      render: text =>
        renderTableAdSelect({ props: this.props, value: text, key: allDictList.upkeepType }),
    },
    {
      title: '支付方式',
      dataIndex: 'payMethod',
      render: text =>
        renderTableAdSelect({ props: this.props, value: text, data: upkeepPayMethod }),
    },
    {
      title: '保养厂/维修厂',
      dataIndex: 'upkeepFactory',
    },
    {
      title: '保养日期/维修日期',
      dataIndex: 'upkeepTime',
    },
    {
      title: '送保人/送修人',
      dataIndex: 'upkeepPerson',
    },
    {
      title: '附件',
      dataIndex: 'attaQuantity',
      render: (text, record) => (
        <FileReader
          type="list"
          count={text}
          urlType="tms"
          params={{ bizId: record.id, fileBizType: 'UPKEEP_MANA' }}
        />
      ),
    },
  ];

  etcColumns = [
    {
      title: '单据号',
      dataIndex: 'etcChangeNo',
      render: (text, record) => this.renderInfo(text, record),
    },
    {
      title: '卡号',
      dataIndex: 'etcNo',
    },
    {
      title: '主车牌',
      dataIndex: 'cartPlateNo',
    },
    {
      title: '所属公司',
      dataIndex: 'ownCompanyName',
    },
    {
      title: '交易省份',
      dataIndex: 'locationName',
    },
    {
      title: '交易性质',
      dataIndex: 'tradingType',
      render: text =>
        renderTableAdSelect({
          props: this.props,
          value: text,
          key: allDictList.etcChangeType,
        }),
    },
    {
      title: '入口时间',
      dataIndex: 'entranceTime',
    },
    {
      title: '入口站',
      dataIndex: 'entranceStation',
    },
    {
      title: ' 出口时间/交易时间',
      dataIndex: 'exportTime',
    },
    {
      title: '出口站/充值地点',
      dataIndex: 'exportStation',
    },

    {
      title: '币种',
      dataIndex: 'currencyType',
      render: text =>
        renderTableAdSelect({
          props: this.props,
          value: text,
          key: allDictList.currencyType,
        }),
    },
    {
      title: '金额',
      dataIndex: 'changeMoney',
    },
    {
      title: '附件',
      dataIndex: 'attaQuantity',
      render: (text, record) => (
        <FileReader
          type="list"
          count={text}
          urlType="tms"
          params={{ bizId: record.id, fileBizType: 'ETC_CHANGE_MANA' }}
        />
      ),
    },
  ];
  //司机证件:
  driverPaperColumns = [
    {
      title: '单号',
      dataIndex: 'papersNo',
      render: (text, record) => this.renderInfo(text, record),
    },
    {
      title: '证件编号',
      dataIndex: 'papersNumber',
    },
    // {
    //   title: '状态',
    //   dataIndex: 'status',
    //   render: text =>
    //     renderTableAdSelect({ props: this.props, value: text, data: paperStatusList }),
    //   width: 100,
    // },
    {
      title: '所属公司',
      dataIndex: 'mdsCompanyName',
      width: 210,
    },
    {
      title: '司机',
      dataIndex: 'driverName',
    },
    {
      title: '证件类型',
      dataIndex: 'papersType',
      width: 100,
      render: text =>
        renderTableAdSelect({ props: this.props, value: text, key: allDictList.papersType }),
    },
    {
      title: '有效期',
      dataIndex: 'effeTimeBegin',
      width: 200,
      render: (_, record) => {
        const { expiryStartTime, expiryEndTime } = record;
        const text = expiryStartTime ? `${expiryStartTime}~${expiryEndTime}` : '';
        return <span title={text}>{text}</span>;
      },
    },
    {
      title: '附件',
      dataIndex: 'attaQuantity',
      width: 80,
      render: (text, record) => (
        <FileReader
          type="list"
          count={text}
          urlType="tms"
          params={{ bizId: record.id, fileBizType: 'DRIVER_PAPERS' }}
        />
      ),
    },
  ];
  //杂费：
  incidentalColumns = [
    {
      title: '单号',
      dataIndex: 'miscellaneousNo',
      width:130,
      render: (text, record) => (
        <AdButton
          mode="a"
          onClick={() => this.showDetail(record.id, record.status)}
          text={text}
          code={codes.showDetail}
        />
      ),
      fixed: this.props.isMobile ? false : true,
    },
    {
      title: '状态',
      dataIndex: 'status',
      render: (text, record) => (
        <AdSelect onlyRead={true} value={text ? text : record.status} data={incidentalStatusList} />
      ),
      width: 100,
    },
    {
      title: '所属公司',
      dataIndex: 'ownCompanyName',
      width: 250,
      render: text => <span title={text}>{text}</span>,
    },
    {
      title: '费用类型',
      dataIndex: 'type',
      render: text =>
        renderTableAdSelect({
          props: this.props,
          value: text,
          key: allDictList.otherFeeType,
        }),
      width: 100,
    },
    {
      title: '付款人', //对应行车档案--车次--杂费--司机
      dataIndex: 'relationObj',
      render: text => <span>{text}</span>,
      width: 150,
    },
    {
      title: '付款日期',
      dataIndex: 'happenTime',
      render: text => <span>{text ? moment(text).format('YYYY-MM-DD') : ''}</span>,
      width: 150,
    },
    {
      title: '金额(元)',
      dataIndex: 'fee',
      render: text => <span>{formatPrice(text)}</span>,
      width: 100,
    },
    {
      title: '币种',
      dataIndex: 'currency',
      render: text =>
        renderTableAdSelect({
          props: this.props,
          value: text,
          key: allDictList.currencyType,
        }),
      width: 100,
    },
    {
      title: '账单号',
      dataIndex: 'billNo',
    },
    {
      title: '来源',
      dataIndex: 'source',
      render: text => (
        <span>{text === 'TRAINS' ? '车次杂费' : text === 'MANAGE' ? '杂费管理' : ''}</span>
      ),
      width: 150,
    },
    {
      title: '备注',
      dataIndex: 'remark',
      render: text => <span title={text}>{text}</span>,
      // width: 100,
    },
    // {
    //   title: '创建人',
    //   dataIndex: 'createBy',
    //   render: text => (
    //     <AdSearch
    //       label="loginName"
    //       name="sysName"
    //       value={this.props.searchValue[text]}
    //       onlyRead={true}
    //     />
    //   ),
    // },
    // {
    //   title: '创建时间',
    //   dataIndex: 'createTime',
    //   render: text => <span>{text ? moment(text).format(formateDateToMin) : ''}</span>,
    // },
    // {
    //   title: '更新人',
    //   dataIndex: 'updateBy',
    //   render: text => (
    //     <AdSearch
    //       label="loginName"
    //       name="sysName"
    //       value={this.props.searchValue[text]}
    //       onlyRead={true}
    //     />
    //   ),
    // },
    // {
    //   title: '更新时间',
    //   dataIndex: 'updateTime',
    //   render: text => <span>{text ? moment(text).format(formateDateToMin) : ''}</span>,
    // },
  ];

  handleOk = () => {
    const { detailId, billDetail, dispatch, setInfoModal, getBillDetails } = this.props;
    const { addSelectedRows } = this.state;
    if (addSelectedRows.length === 0) return;
    const type = billDetail[detailId].type;
    let checkBill = true;
    if (type === 'OIL') {
      checkBill = this.checkOilBill();
    }
    if (!checkBill) return;
    dispatch({
      type: allDispatchType.addInfoDetail,
      payload: { detailId: addSelectedRows.map(v => v.id), id: detailId },
      callback: data => {
        if (!data) return;
        setInfoModal();
        getBillDetails(detailId);
        this.selectBillDetailAndInfo(detailId, type);
        getBillVehicleIDetails(dispatch, detailId, type);
        type === 'OIL' && getBillOilDetails(dispatch, detailId);
      },
    });
  };

  checkOilBill = () => {
    const { addSelectedRows } = this.state;
    const oilType = vitifyCheck({
      selectedRows: addSelectedRows,
      key: 'oilType',
      warn: '加油方式不同，不能合并生成帐单！',
    });
    if (!oilType) return false;
    if (oilType[0] === '月结') {
      const oilSiteName = vitifyCheck({
        selectedRows: addSelectedRows,
        key: 'oilSiteName',
        warn: '月结加油，加油站名称必须相同！',
      });
      if (!oilSiteName) return false;
    }
    return true;
  };

  getColumnByType = () => {
    const { billDetail, detailId } = this.props;
    const detail = billDetail[detailId] || {};
    const type = detail.type;
    let columns = [];
    switch (type) {
      case 'OIL':
        columns = this.oilColumns;
        break;
      case 'INSURANCE':
        columns = this.insuranceColumns;
        break;
      case 'ANNUALAUDIT':
        columns = this.verificationColumns;
        break;
      case 'UPKEEP':
        columns = this.upkeepColumns;
        break;
      case 'ETCCHANGE':
        columns = this.etcColumns;
        break;
      case 'DRIVERPAPER':
        columns = this.driverPaperColumns;
        break;
      case 'MISCELLANEOUS': //杂费
        columns = this.incidentalColumns;
        break;
      default:
        break;
    }
    return columns;
  };

  /**
   * form 查找条件 重置
   */
  handleFormReset = () => {
    const { form } = this.props;
    form.resetFields();
    this.setState({
      formValues: {},
      cars: [],
      drivers: [],
      company: [],
    });
    this.seleceBillAddInfo();
  };

  /**
   * form 查找条件 查询
   */
  handleSearch = values => {
    const { cars, drivers, company } = this.state;
    const { type } = this.props;
    const { driverId, vehicleId, ...params } = values;
    //司机证件
    if (type == 'DRIVERPAPER' && drivers.length > 0) {
      params.driverId = drivers[0].id;
      //杂费
    } else if (type == 'MISCELLANEOUS' && company.length > 0) {
      params.mdsCompanyId = company[0].id;
    } else if (cars.length > 0) {
      params.vehicleId = cars[0].id;
    }
    this.seleceBillAddInfo(params);
  };

  /**
   * table 表格 分页操作
   */
  handleStandardTableChange = param => {
    const { detailId } = this.state;
    const { type } = this.props;
    this.selectBillDetailAndInfo(detailId, type, param);
  };
  handleStandardTableChangeAdd = param => {
    this.seleceBillAddInfo(param);
  };
  getValue = (values, type) => {
    this.setState({
      [type]: values,
    });
  };
  formatBillNo = commonParams => {
    const { billDetail, detailId, dictObject, form } = this.props;
    const detail = billDetail[detailId] || {};
    const type = detail.type;
    let code = ''; //code为 类型的单据号 字段
    let otherFormItem = [];
    switch (type) {
      case 'OIL':
        code = 'oilNo';
        otherFormItem = [
          [
            <AntdFormItem label="加油方式" code="oilType" {...commonParams}>
              <AdSelect isExist={true} data={dictObject[allDictList.oilType]} />
            </AntdFormItem>,
          ],
          [
            <AntdFormItem label="加油站" code="oilSiteName" {...commonParams}>
              <Input />
            </AntdFormItem>,
            
          ],
          ['operatorButtons']
        ];
        break;
      case 'INSURANCE':
        code = 'insuranceNo';
        otherFormItem = [
          [
            <AntdFormItem label="保险类型" code="insuranceTypeCode" {...commonParams}>
              <AdSelect isExist={true} data={dictObject[allDictList.insuranceType]} />
            </AntdFormItem>,
          ],
          ['operatorButtons'],
        ];
        break;
      case 'ANNUALAUDIT':
        code = 'annualNo';
        otherFormItem = [
          [
            <AntdFormItem label="类型" code="annualAuditType" {...commonParams}>
              <AdSelect isExist={true} data={dictObject[allDictList.inspectionType]} />
            </AntdFormItem>,
          ],
          ['operatorButtons'],
        ];
        break;
      case 'UPKEEP':
        code = 'upkeepNo';
        otherFormItem = [
          [
            <AntdFormItem label="保养类型" code="upkeepTypeCode" {...commonParams}>
              <AdSelect isExist={true} data={dictObject[allDictList.upkeepType]} />
            </AntdFormItem>,
          ],
          ['operatorButtons'],
        ];
        break;
      case 'ETCCHANGE':
        code = 'etcChangeNo';
        otherFormItem = [
          [
            <AntdFormItem label="交易性质" code="tradingType" {...commonParams}>
              <AdSelect isExist={true} data={dictObject[allDictList.etcChangeType]} />
            </AntdFormItem>,
          ],
          ['operatorButtons'],
        ];
        break;
      case 'DRIVERPAPER':
        code = 'papersNo';
        otherFormItem = [
          [
            <AntdFormItem label="证件类型" code="papersType" {...commonParams}>
              <AdSelect payload={{ code: allDictList.papersType }} />
            </AntdFormItem>,
          ],
          ['operatorButtons'],
        ];
        break;
      case 'MISCELLANEOUS':
        code = 'miscellaneousNo';
        otherFormItem = ''
        // [
          
        //    ['operatorButtons']
        // ];
        break;
      default:
        break;
    }
    return [code, otherFormItem];
  };

  render() {
    const {
      billInfo,
      form,
      setInfoModal,
      visible,
      loading,
      addLoading,
      onSelectRow,
      billAddInfo,
      mode,
      type,
      status,
      dictObject,
      open,
    } = this.props;

    const { selectedRows, addSelectedRows, detailId, checkId, visibleDetail } = this.state;

    const commonParams = {
      getFieldDecorator: form.getFieldDecorator,
    };
    let firstFormItem = [];
    let secondFormItem = [];
    let otherFormItem = [];
    const paramsType = this.formatBillNo(commonParams);

    firstFormItem = (
      <AntdFormItem label="单据号" code={paramsType[0] || 'a'} {...commonParams}>
        <Input />
      </AntdFormItem>
    );
    if (type == 'DRIVERPAPER') {
      secondFormItem = (
        <AntdFormItem label="司机" code="driverId" {...commonParams}>
          <SearchSelect
            multiple={false} // 是否多选
            dataUrl="tms/tms-driver/selectList"
            url="tms/tms-driver/viewDetails"
            selectedData={this.state.drivers} // 选中值
            columns={columnsDriver} // 表格展示列
            onChange={values => this.getValue(values, 'drivers')} // 获取选中值
            id="driverPaper_list_3"
            scrollX={500}
            allowClear={true}
          />
        </AntdFormItem>
      );
    } else if (type == 'MISCELLANEOUS') {
      //杂费
      secondFormItem =''
      // secondFormItem = (
      //   <AntdFormItem label="所属公司" code="mdsCompanyId" {...commonParams}>
      //     <SearchSelect
      //       dataUrl={allUrl.companyList}
      //       selectedData={this.state.company} // 选中值
      //       multiple={false} // 是否多选
      //       showValue="customerName"
      //       searchName="customerName"
      //       columns={supplierColumns} // 表格展示列
      //       onChange={values => this.getValue(values, 'company')} // 获取选中值
      //       scrollX={400}
      //       id="IncidentalOperate_2"
      //       // disabled={disabled}
      //     />
      //   </AntdFormItem>
      // );
    } else {
      secondFormItem = (
        <AntdFormItem label="车牌号" code="vehicleId" {...commonParams}>
          <SearchSelect
            dataUrl="tms/tms-oil/selectOilVehicle"
            url="tms/tms-oil/selectOilVehicleView_s" // selectedData只只有id时需要传url
            selectedData={this.state.cars} // 选中值
            multiple={false} // 是否多选
            showValue="cartPlateOneNo"
            searchName="cartPlate"
            columns={columns1} // 表格展示列
            onChange={values => this.getValue(values, 'cars')} // 获取选中值
            scrollX={480}
            id="bill_billInfo_1"
            allowClear={true}
          />
        </AntdFormItem>
      );
    }

    const selectFormParams = {
      firstFormItem,
      secondFormItem,
      // otherFormItem: paramsType[1] || [],
      otherFormItem: this.formatBillNo(commonParams)[1] ||[],
      form,
      className: this.className,
      handleFormReset: this.handleFormReset,
      handleSearch: this.handleSearch,
      toggleForm: expandForm => {
        this.handleStateChange([{ expandForm }]);
      },
      code: codes.select,
    };

    return (
      <Fragment>
        {visible && (
          <AdModal
            visible={visible}
            title={`新增明细`}
            onOk={this.handleOk}
            onCancel={() => {
              setInfoModal();
            }}
            width="80%"
          >
            <div className="archives_oilInfo">
              <SelectForm {...selectFormParams} />
              <StandardTable
                loading={addLoading}
                selectedRows={addSelectedRows}
                onSelectRow={addSelectedRows => {
                  this.handleStateChange([{ addSelectedRows }]);
                }}
                scrollY={300}
                data={billAddInfo}
                columns={this.getColumnByType()}
                scrollX={2000}
                onPaginationChange={this.handleStandardTableChangeAdd}
              />
            </div>
          </AdModal>
        )}
        {visibleDetail && (
          <AdModal
            visible={visibleDetail}
            title={`明细详情`}
            onOk={this.handleOk}
            onCancel={() => {
              this.handleCandle();
            }}
            width="80%"
            footer={null}
          >
            <BillInfoDetail detailId={checkId} type={type} open={open} />
          </AdModal>
        )}

        <StandardTable
          disabledRowSelected={mode === 'detail' || status}
          loading={loading}
          selectedRows={selectedRows}
          onSelectRow={selectedRows => {
            onSelectRow && onSelectRow(selectedRows);
            this.handleStateChange([{ selectedRows }]);
          }}
          code={'billInfoDetail'}
          data={billInfo[detailId] || {}}
          columns={this.getColumnByType()}
          scrollY={500}
          scrollX={2000}
          scrollY={200}
          code="BillInfo"
          onPaginationChange={this.handleStandardTableChange}
        />
      </Fragment>
    );
  }
}
